package com.huidao.data;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.huidao.domain.Food;
import com.huidao.domain.FoodCategory;
import com.huidao.domain.MealsSet;

public class FoodDb {
	private static List<Food> foodList = new ArrayList<Food>();
	private static List<MealsSet> mealsSetList = new ArrayList<MealsSet>();
	private static BufferedWriter bw;
	private static BufferedReader br;
	static {
		getFood();
	}

	// 初始化菜品信息
	public static void getFood() {
		try {
			try {
				bw = new BufferedWriter(new FileWriter("food.txt"));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			br = new BufferedReader(new FileReader("food.txt"));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		FoodCategory fc1 = new FoodCategory("IP001", "盖浇饭");
		FoodCategory fc2 = new FoodCategory("IP002", "汤类");
		FoodCategory fc3 = new FoodCategory("IP003", "面食");
		FoodCategory fc4 = new FoodCategory("IP004", "饮料");
		Food f1 = new Food("0001", "西红柿炒蛋", fc1, 14.5, 12);
		Food f2 = new Food("0002", "红烧肉", fc1, 20.0, 18.0);
		Food f3 = new Food("0003", "小炒肉", fc1, 14.0, 12.5);
		Food f4 = new Food("004", "麻婆豆腐", fc1, 10.0, 9.5);
		Food f5 = new Food("005", "土豆牛肉", fc1, 21.5, 20.0);
		Food f6 = new Food("006", "辣子鸡丁", fc1, 18.5, 17.0);
		Food f7 = new Food("007", "红烧鱼块", fc1, 18.5, 17.0);
		Food f8 = new Food("0008", "排骨汤", fc2, 12.0, 10.5);
		Food f9 = new Food("0009", "老鸭茶树菇", fc2, 14.5, 12.5);
		Food f10 = new Food("0010", "牛肉炒面", fc3, 14.0, 12.5);
		Food f11 = new Food("0011", "尖椒炒蛋刀削面", fc3, 11.0, 10.0);
		Food f12 = new Food("0012", "可乐", fc4, 3.5, 2.5);
		Food f13 = new Food("0013", "雪碧", fc4, 4.0, 2.5);
		Food f14 = new Food("0014", "王老吉", fc4, 4.0, 3.5);
		Food[] foodMS1 = { f2, f12 };
		Food[] foodMS2 = { f6, f14 };
		Food[] foodMS3 = { f7, f13 };
		MealsSet ms1 = new MealsSet("MS001", "红烧肉套餐", foodMS1, 21.5);
		MealsSet ms2 = new MealsSet("MS002", "辣子鸡丁套餐", foodMS2, 20.0);
		MealsSet ms3 = new MealsSet("MS003", "红烧鱼块套餐", foodMS3, 20.0);
		foodList.add(f1);
		foodList.add(f2);
		foodList.add(f3);
		foodList.add(f4);
		foodList.add(f5);
		foodList.add(f6);
		foodList.add(f7);
		foodList.add(f8);
		foodList.add(f9);
		foodList.add(f10);
		foodList.add(f11);
		foodList.add(f12);
		foodList.add(f13);
		foodList.add(f14);
		mealsSetList.add(ms1);
		mealsSetList.add(ms2);
		mealsSetList.add(ms3);
		for (Food food : foodList) {
			try {
				bw.write(food.toString());
				bw.newLine();
				bw.flush();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		for (MealsSet mealsSet : mealsSetList) {
			try {
				bw.write(mealsSet.toString());
				bw.newLine();
				bw.flush();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * @return the mealsSetList
	 */
	public static List<MealsSet> getMealsSetList() {
		return mealsSetList;
	}

	/**
	 * @return the foodList
	 */
	public static List<Food> getFoodList() {
		return foodList;
	}
	

	/**
	 * @return the bw
	 */
	public static BufferedWriter getBw() {
		return bw;
	}

	/**
	 * @return the br
	 */
	public static BufferedReader getBr() {
		return br;
	}

}
